import java.util.Iterator;
import java.util.LinkedList;

//ArrayList 必须开辟连续空间 查询快 增删慢
//LinkedList 无需开辟连续空间，查询慢，增删快

public class Demo6LinkedList {
    public static void main(String[] args) {
        LinkedList linkedList=new LinkedList();

        Student s1=new Student("刘德华",20);
        Student s2=new Student("蒋恬",21);
        Student s3=new Student("陈海",22);
        linkedList.add(s1);
        linkedList.add(s2);
        linkedList.add(s3);

        System.out.println(linkedList.size());
        System.out.println(linkedList);

        linkedList.remove(new Student("刘德华",20));
        System.out.println(linkedList);


        System.out.println("------------for遍历----------");
        for (int i = 0; i < linkedList.size(); i++) {
            System.out.println(linkedList.get(i));
        }


        System.out.println("------------加强for遍历----------");
        for (Object object :
                linkedList) {
            System.out.println(object);
        }

        System.out.println("-----------使用迭代器遍历--------");

        Iterator iterator =linkedList.iterator();

        while(iterator.hasNext())
        {
            System.out.println(iterator.next());
        }

        System.out.println(linkedList.contains(s1));
        System.out.println(linkedList.isEmpty());

        System.out.println(linkedList.indexOf(s2));
    }
}
